home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / FileHistory / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  5KB  |  213 lines

  1. /* **** HBBS Door Code****************************************************** */
  2.  
  3. /*
  4.   FileHistory
  5.   ===========
  6.  
  7.     Creates a file called <Filename>.History containing info about the bbs, user, time
  8.     that the file was uploaded to.
  9.  
  10.     Then it add this back the .LHA archive
  11.  
  12.     So, when the file has been traded around a bit you can see exactly where the
  13.     file has been, who got it first etc..  So other util writers could create
  14.     a program to provide statistics on which bbs gets the warez first, who's the
  15.     fastest trader etc...
  16.  
  17.   Version
  18.   =======
  19.  
  20.     1.0
  21.  
  22.   Options
  23.   =======
  24.  
  25.     N_ND->ActiveDoor->SystemOptions
  26.     -------------------------------
  27.  
  28.     none
  29.  
  30.     Command Line Arguments
  31.     ----------------------
  32.  
  33.     see ExtractDIZ
  34.  
  35.   ToDo
  36.   ====
  37.  
  38.     Support other files as well as LHA's
  39.  
  40.  
  41.  
  42. */
  43.  
  44. /* **** Includes *********************************************************** */
  45.  
  46. #include <exec/types.h>
  47. #include <exec/memory.h>
  48. #include <dos/dos.h>
  49. #include <clib/exec_protos.h>
  50. #include <clib/dos_protos.h>
  51. #include <clib/alib_protos.h>
  52.  
  53. #include <stdlib.h>
  54. #include <string.h>
  55. #include <stdio.h>
  56. #include <ctype.h>
  57. #include <time.h>
  58.  
  59. #include <HBBS/ANSI_Codes.h>
  60. #include <HBBS/Defines.h>
  61. #include <HBBS/Access.h>
  62. #include <HBBS/types.h>
  63. #include <HBBS/structures.h>
  64. #include <HBBS/hbbscommon_protos.h>
  65. #include <HBBS/hbbscommon_pragmas.h>
  66. #include <HBBS/Hbbsnode_protos.h>
  67. #include <HBBS/Hbbsnode_pragmas.h>
  68. #include <HBBS/release.h>
  69. char *versionstr="$VER: FileHistory "RELEASE_STR;
  70.  
  71. /* **** Variables ********************************************************** */
  72.  
  73.  
  74. struct Library *HBBSCommonBase  = NULL;
  75. struct Library *HBBSNodeBase    = NULL;
  76.  
  77. struct BBSGlobalData *BBSGlobal = NULL;
  78. struct NodeData *N_ND           = NULL;
  79. int    N_NodeNum                = -1;
  80. char   outstr[1024];
  81.  
  82. long __stack=16*1024; // increse this in 4k incrments if you suffer from
  83.                       // random/suprious crashings after or during the running
  84.                       // of your door.
  85.  
  86. int    gargc;         // these are just copies of main()'s argc and argv..
  87. char   **gargv;
  88.  
  89. /* **** Functions ********************************************************** */
  90.  
  91.  
  92. #ifdef __SASC
  93. int CXBRK(void) { return(0); }
  94. int _CXBRK(void) { return(0); }
  95. void chkabort(void) {}
  96. #endif
  97.  
  98. static VOID cleanup(ULONG num)
  99. {
  100.   if (HBBSNodeBase)
  101.   {
  102.     HBBS_CleanUpDoor();
  103.     CloseLibrary (HBBSNodeBase);
  104.   }
  105.  
  106.   if (HBBSCommonBase)
  107.   {
  108.     HBBS_CleanUpCommon();
  109.     CloseLibrary (HBBSCommonBase);
  110.   }
  111.  
  112.   if (num) printf("Door Error = %d\n",num);
  113.  
  114.   exit(0);
  115. }
  116.  
  117. static VOID init(char *name)
  118. {
  119.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  120.   {
  121.     cleanup(1);
  122.   }
  123.  
  124.   if (!(HBBS_InitCommon()))
  125.   {
  126.     cleanup(2);
  127.   }
  128.  
  129.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  130.   {
  131.     cleanup(3);
  132.   }
  133.  
  134.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  135.   {
  136.     cleanup(4);
  137.   }
  138.   SetProgramName(name);
  139. }
  140.  
  141. /* **** DoorMain *********************************************************** */
  142.  
  143. void DoorMain( void )
  144. {
  145.   char fname[30];
  146.   char timestr[20];
  147.   char datestr[20];
  148.  
  149.   // LHA file ?
  150.   if (gargc>5 && stricmp(gargv[6],"LHA")==0)
  151.   {
  152.     DOOR_WriteText("     _   _   _   _                                       _   _   _   _   _\r\n"
  153.                    "\\_/ \\_/ \\_/ \\_/ \\_/ \\-=[ LHA History V1.0 by Hydra/LSD ]=-/ \\_/ \\_/ \\_/ \\_/ \\_/\r\n");
  154.  
  155.     // what's the filename?
  156.     sprintf(fname,"T:%s.history",gargv[2]);
  157.  
  158.     // delete it from t: if it's already there..
  159.     DeleteFile(fname);
  160.  
  161.     // is there one in the LHA file already ?
  162.     sprintf(outstr,"LHA <>nil: e %s%s %s.History T:",gargv[4],gargv[2],gargv[2]);
  163.     HBBS_RunDOSCMD(outstr,FALSE);
  164.  
  165.     // create the string to add to the file
  166.  
  167.     HBBS_GetDate(datestr);
  168.     HBBS_GetTime(timestr);
  169.     sprintf(outstr,"Uploaded to %s by %s at %s on %s\n",BBSGlobal->BBSName,N_ND->User.CallData.Handle,timestr,datestr);
  170.  
  171.     // add it to the file
  172.  
  173.     HBBS_AppendStrToFile(fname,outstr);
  174.  
  175.     // make sure the file is there (no errors)
  176.  
  177.     if (PathOK(fname))
  178.     {
  179.       // and add it back to the archive.
  180.  
  181.       sprintf(outstr,"LHA <>nil: u %s%s %s",gargv[4],gargv[2],fname);
  182.       HBBS_RunDOSCMD(outstr,FALSE);
  183.  
  184.       // delete it from t:
  185.       DeleteFile(fname);
  186.     }
  187.   }
  188. }
  189.  
  190. int main(int argc,char **argv)
  191. {
  192.   gargc=argc;
  193.   gargv=argv;
  194.  
  195.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  196.   {
  197.     printf("Invalid/No Paramaters for door!\n");
  198.     exit (20);
  199.   }
  200.   init("FileHistory");
  201.  
  202.   if (BBSGlobal=HBBS_GimmeBBS())
  203.   {
  204.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  205.     {
  206.       DoorMain();
  207.     }
  208.   }
  209.   cleanup(0);
  210. }
  211.  
  212. /* **** End Of File ******************************************************** */
  213.